<?php

namespace App\Http\Requests\Admin;

use App\Models\Admin;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class AdminRequest extends FormRequest
{
	/**
	 * Determine if the user is authorized to make this request.
	 *
	 * @return bool
	 */
	public function authorize()
	{
		return true;
	}

	/**
	 * Get the validation rules that apply to the request.
	 *
	 * @return array
	 */
	public function rules()
	{
		return [
			'username'  => 'bail|required|unique:admin,username|string|max:20|alpha_dash',
			'password'  => 'bail|required|string|max:16',
			'nickname'  => 'bail|required|unique:admin,username|string|max:20',
			'age'       => 'bail|sometimes|nullable|integer|max:121',
			'role_id'   => 'bail|required|array',
			'role_id.*' => 'required|exists:role,id|integer',
			'sex'       =>
				[
					'integer',
					Rule::in(['1', '0'])
				],
			'status'    =>
				[
					'integer',
					Rule::in(['1', '0'])
				],

		];
	}

	public function attributes()
	{
		return [
			'username' => '用户名',
			'password' => '密码',
			'nickname' => '昵称',
			'age'      => '年龄',
			'sex'      => '性别',
			'status'   => '用户状态',
			'role_id'  => '角色'
		];
	}

	public function messages()
	{
		return [
			'role_id.*' =>'角色未勾选或不存在',
		];
	}
}
